<?php
class Impact_View_Helper_Cycle
{
    protected $_view;

    public function cycle($variableName, $values)
    {
        $valueArray = (array) $values;

        if (count($valueArray) == 0) {
            return '';
        }

        $indexVariableName = $variableName . 'Index';

        if (!isset($this->_view->$variableName)) {
            $this->_view->$variableName = $valueArray[0];
            $this->_view->$indexVariableName = 1;
        } else {
            if ($this->_view->$indexVariableName == count($valueArray)) {
                $this->_view->$variableName = $valueArray[0];
                $this->_view->$indexVariableName = 1;
            } else {
                $this->_view->$variableName = $valueArray[$this->_view->$indexVariableName];
                $this->_view->$indexVariableName++;
            }
        }

        return $this->_view->$variableName;
    }

    public function setView(Zend_View_Interface $view)
    {
        $this->_view = $view;
    }
}

// vim: sw=4:ts=4:sts=4:et
